clc; clear; close all;

% 迭代参数
N_iter = 600;
N_discard = 400;
m = 2;

% 参数范围
r_list = linspace(3, 4, 50);
b_list = linspace(0, 30, 50);

% 初始化结果矩阵
SE_mat = zeros(length(r_list), length(b_list));

% 固定初值（实数部分，虚部为0）
x0 = 0.463442265 + 0i;
y0 = 0.04532285  + 0i;
z0 = 0.002136285 + 0i;

parfor ir = 1:length(r_list)
    r = r_list(ir);
    SE_tmp = zeros(1, length(b_list));
    for ib = 1:length(b_list)
        b = b_list(ib);

        x = x0; y = y0; z = z0;
        X = zeros(N_iter,1);

        for k = 1:N_iter
            state = QuantumLogistic(x, y, z, r, b);
            x = state(1);
            y = state(2);
            z = state(3);
            X(k) = real(x); % 取实部计算熵
        end

        data = X(N_discard+1:end);
        r_tol = 0.2 * std(data);
        SE_tmp(ib) = sample_entropy(data, m, r_tol);
    end
    SE_mat(ir, :) = SE_tmp;
end

% 0-1归一化
SE_min = min(SE_mat(:));
SE_max = max(SE_mat(:));
SE_norm = (SE_mat - SE_min) / (SE_max - SE_min);

% 网格坐标
[B_grid, R_grid] = meshgrid(b_list, r_list);

% 绘图
figure;
surf(B_grid, R_grid, SE_norm', 'EdgeColor', 'none');
set(gca, 'YDir', 'reverse'); 
xlabel('r');
ylabel('b');
zlabel('SE');
title('Quantum Logistic 系统的SE复杂度');
colorbar;
view(45,30);
grid on;

